package rocketmq.demo.oneway.trans;

import java.util.Date;

import com.alibaba.rocketmq.client.producer.DefaultMQProducer;
import com.alibaba.rocketmq.common.message.Message;
import com.alibaba.rocketmq.remoting.common.RemotingHelper;

/**
 * <pre>
 * One-way transmission 单向传输
 * 
 * Application: One-way transmission is used for cases
 * requiring moderate reliability, such as log collection.
 * </pre>
 */
public class OnewayProducer2 {
	public static void main(String[] args) throws Exception {
		// Instantiate with a producer group name.
		DefaultMQProducer producer = new DefaultMQProducer("testGroup");
		// 指定nameServer的地址 （测试时在代码中指定）
		producer.setNamesrvAddr("127.0.0.1:9876");
		// Launch the instance.
		producer.start();
		for (int i = 0; i < 10; i++) {
			// Create a message instance
			// specifying topic, tag and message body.
			String content = "你好  RocketMQ, " + new Date().getTime() + "-->" + i;
			Message message = new Message("TopicOneWay2", "testTag2", content.getBytes(RemotingHelper.DEFAULT_CHARSET));
			// Call send message to deliver message to one of brokers.
			producer.sendOneway(message);
		}
		// Shut down once the producer instance is not longer in use.
		producer.shutdown();
	}
}
